﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YunZuan.Models.Entities;

namespace YunZuan.Models
{
    public class PageParamOfInventory : IPageParam
    {
         
        public int pageSize { get; set; } = 50; 



        public int pageIndex { get; set; } = 1;
         

        public int PageCount { get; set; }

        public string[] Shape { get; set; }
        private string[] _color;
        public string[] Color
        {
            get
            {

                //if (_color == null)
                //{
                //    if (IntensityParam != null && OvertoneParam != null)
                //    {
                //        _color = new string[IntensityParam.Length + OvertoneParam.Length];
                //        IntensityParam.CopyTo(this._color, 0);
                //        OvertoneParam.CopyTo(this._color, IntensityParam.Length);
                //    }
                //    else if (IntensityParam != null)
                //    {
                //        _color = new string[IntensityParam.Length];
                //        IntensityParam.CopyTo(this._color, 0);
                //    }
                //    else if (OvertoneParam != null)
                //    {
                //        _color = new string[OvertoneParam.Length];
                //        OvertoneParam.CopyTo(this._color, 0);
                //    }

                //}
                return this._color;
            }
            set
            {
                this._color = value;
            }
        }
        public string[] Clarity { get; set; }
        public string[] Cut { get; set; }
        public string[] Polish { get; set; }
        public string[] Symmetry { get; set; }
        public string[] Fluorescence { get; set; }

        public string[] CertType { get; set; }

        private string[] _CertNo;
        public string[] CertNo
        {
            get
            {
                if (_CertNo != null)
                {
                    _CertNo = _CertNo.Where(s => !string.IsNullOrEmpty(s)).ToArray();
                }
                return _CertNo;

            }
            set { _CertNo = value; }
        }
        //原货号 12-24
        private string[] _originSN;
        public string[] OriginSN
        {
            get
            {
                if (_originSN != null)
                {
                    _originSN = _originSN.Where(s => !string.IsNullOrEmpty(s)).ToArray();
                }
                return _originSN;
            }
            set { _originSN = value; }
        }
        private string[] _milky;
        public string[] Milky
        {
            get
            {
                return MilkysHues;
            }
            set
            {
                this._milky = value;
            }
        }
        private string[] _hue;
        public string[] Hue
        {
            get
            {
                return MilkysHues;
            }
            set
            {
                this._hue = value;
            }
        }
        public string[] Address { get; set; }
        public float WeightMin { get; set; }
        public float WeightMax { get; set; }
        private string _SN;
        public string SN { 
            get {
                if (_SN == ""||_SN==null) 
                    return null;
                return _SN.TrimStart(' ').TrimEnd(' ');
            }
            set { _SN = value; }
        }
        public int UserID { get; set; }
        public string SortColumn { get; set; }
        public string SortDirect { get; set; }


        public int CustomerID { get; set; }
        public string[] Place { get; set; }
        public int? IsFancy { get; set; }
        public int? OnShelves { get; set; } //12-27 上/下架
        public string IntensitySQL { get; set; }
        public string OvertoneSQL { get; set; }

        public string[] MilkysHues { get; set; }
        public string IntensityMHSQL { get; set; }
        public readonly bool useDict = true;
        /// <summary>
        /// 现货：0.否，1.是
        /// </summary>
        public int Stock { get; set; }
        public int[] ID { get; set; }
        public string[] GoodsStatus { get; set; }

        //数据仓库的数据类型为[]
        private string[] weight;
        public string[] Weight
        {
            get
            {
                if (WeightMax > 0) this.weight = new string[] { WeightMin.ToString(), WeightMax.ToString() };
                else this.weight = null;

                return weight;
            }
            set
            {
                this.weight = value;
            }
        }
        //数据仓库的数据类型为[]
        private string[] sort;
        public string[] Sort
        {
            get
            {
                if (SortColumn == null || SortDirect == null) this.sort = null;
                else this.sort = new string[] { SortColumn == "Weight" ? "Weight" : "OriginUSDPerGrain", SortDirect };  //仓库始终按总价排序,重量列外
                return sort;
            }
            set
            {
                this.sort = value;
            }
        }

        private string isTempFancy { get; set; }
        public string IsTempFancy
        {
            get
            {
                this.isTempFancy = IsFancy.ToString();
                return isTempFancy;
            }
            set
            {
                this.isTempFancy = value;
            }
        }
        public string SupplierCode { get; set; }
        private string[] supplier { get; set; }
        public string[] Supplier
        {
            get
            {
                if (SupplierCode == "stock")
                    this.supplier = CachePriorities();
                return supplier;
            }
            set
            {
                this.supplier = value;
            }
        }

        public string[] CachePriorities()
        {
            if (HttpRuntime.Cache.Get("Priorities") == null)
            {
                //get string[] 
                string[] strArray = GetSupplierCodeList();
                HttpRuntime.Cache.Insert("Priorities", strArray, null, DateTime.Now.AddSeconds(60000), TimeSpan.Zero);
                return strArray;

            }
            else
                return HttpRuntime.Cache.Get("Priorities") as string[];
        }
        //得到所有现货供应商 8-26 YZ 在Yunzuan.Foundation里面，现在是Yunzuan.Foundation引用Yunzuan.Models
        public string[] GetSupplierCodeList()
        {
            //IList<HashResult> list = YZ.Database.QueryForList<HashResult>("Supplier.GetSupplierCodeList", null);
            //string[] codes = new string[list.Count];
            //for (int i = 0; i < list.Count; i++)
            //{
            //    codes[i] = list[i]["SupplierCode"].ToString();
            //}
            //return codes;
            return null; //---------------------------
        }


        public string[] FancyStrength { get; set; }
        public string[] FancyColor { get; set; }
        public string WithinMinutes { get; set; }
        //自己拥有的货（此处指上传的） 
        public bool IsSelfStok { get; set; } 
        public string[] SecondSN { get;set; }
        /// <summary>
        /// onlyCount: 是否只统计数量，注意：limit还是会生效的（当limit为1时，count不会大于1），默认：false
        /// </summary>
        public bool onlyCount { get; set; }




        //private Dictionary<string, string[]> _alias;
        public Dictionary<string, string[]> alias { get; set; }
        public Dictionary<string, string[]> exclude { get; set; }
        private Dictionary<string, string[]> _regexp;
        public Dictionary<string, string[]> regexp
        {
            get
            {
                Dictionary<string, string[]> dss = new Dictionary<string, string[]>();
                if (CertNo == null && SN == null && OriginSN == null) this._regexp = null;
                else
                {
                    if (CertNo != null)
                        dss.Add("CertNo", CertNo);
                    if (SN != null)
                        dss.Add("SN", SN.Split(' '));
                    if (OriginSN != null)
                        dss.Add("OriginSN", OriginSN);
                    this._regexp = dss;
                }
                return _regexp;
            }
            set
            {
                this._regexp = value;
            }
        }
        public int IsStock { get; set; }
        private string receiptStatus;

        public string ReceiptStatus
        {
            get { return receiptStatus; }
            set { receiptStatus = value; }
        }
        private string purchaseSupplier;

        public string PurchaseSupplier
        {
            get { return purchaseSupplier; }
            set { purchaseSupplier = value; }
        }
        private string status;

        public PageParamOfInventory()
        {
        }

        public string Status
        {
            get { return status; }
            set { status = value; }
        }

        public string PurchaseTime { get; set; }

        public string ArrivalTime { get; set; }

        public string Tag { get; set; }
    }
}
